package com.china.produce;

import com.china.produce.service.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2022/12/9
 */
//@RunWith(SpringRunner.class)
//@SpringBootTest
public class SynchronizedDemo1 {
//
//    @Resource
//    private UserService userService;

//    @Test
//    public synchronized void method() {
//        System.out.println("synchronized 方法");
//    }
//
//    @Test
//    public void method2() {
//        synchronized (this) {
//            System.out.println("66666");
//        }
//    }
    private static Boolean flag = true;

    private static AtomicInteger num = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {

        for (int j = 0; j < 5; j++) {
            new Thread(() -> {
                for (int i = 0; i < 1000; i++) {
                    num.incrementAndGet();
                }
            }).start();
        }

        TimeUnit.SECONDS.sleep(3);
        System.out.println(num.get());
    }

}
